#include "TwSamplePCH.h"
#include "TwDefines.h"
#include "TwFps.h"
#include "TwDeviceManager.h"

TwFps::TwFps()
: mLastTime(0)
, mFrameCount(0)
, mSampleRate(500)
, mFps(0.0f)
{

}

TwFps::~TwFps()
{

}

void TwFps::update(TimeValue t)
{
	++mFrameCount;
	TimeValue escaped = t - mLastTime;
	if (escaped > mSampleRate)
	{
		mFps = (float)mFrameCount / ((float)escaped * 0.001f);
		mFrameCount = 0;
		mLastTime = t;
	}
}

float TwFps::getFps() const
{
	return mFps;
}
